package com.igeek.ch02.controller;

import com.igeek.ch02.common.CommonResult;
import com.igeek.ch02.entity.User;
import com.igeek.ch02.service.UserService;
import com.igeek.ch02.utils.JSONUtils;
import com.igeek.ch02.vo.PageVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet(name = "UserViewAllServlet", urlPatterns = "/userViewAll")
public class UserViewAllServlet extends HttpServlet {

    private UserService userService =new UserService();



    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        //request.setCharacterEncoding("UTF-8");
        //response.setContentType("application/json;charset=UTF-8");

        int current = Integer.parseInt(request.getParameter("current"));

        PageVO<User> pageVO=userService.fenye(current);

        CommonResult commonResult=new CommonResult(200,"查询列表成功",pageVO);

        JSONUtils.writeJson(response,commonResult);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        this.doPost(request,response);
    }



}
